<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="合同名称" prop="contractName">
        <el-input
            v-model="queryParams.contractName"
            placeholder="请输入合同名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
            v-model="queryParams.customerName"
            placeholder="请输入客户名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="itemName">
        <el-input
            v-model="queryParams.itemName"
            placeholder="请输入项目名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="itemNo">
        <el-input
            v-model="queryParams.itemNo"
            placeholder="请输入项目编号"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单店名称" prop="shop">
        <el-input
            v-model="queryParams.shop"
            placeholder="请输入单店名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="noticeList" highlight-current-row @current-change="handleCurrentChange">
      <el-table-column label="序号" align="center" prop="index" width="60" type="index"/>
      <el-table-column label="项目编号" align="center" prop="itemNo" width="150" show-overflow-tooltip/>
      <el-table-column label="项目名称" align="center" prop="itemName" width="150" show-overflow-tooltip/>
      <el-table-column label="客户名称" align="center" prop="customerName" width="150" show-overflow-tooltip/>
      <el-table-column label="合同编号" align="center" prop="contractNo" width="150" show-overflow-tooltip/>
      <el-table-column label="合同名称" align="center" prop="contractName" width="150" show-overflow-tooltip/>
      <el-table-column label="单店名称" align="center" prop="shop" show-overflow-tooltip/>
      <el-table-column label="维保周期" align="center" prop="maintenanceCycle" show-overflow-tooltip>
        <template #default="scope">
          {{ scope.row.maintenanceCycle }}个月
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="maintenanceStartDate" width="150" show-overflow-tooltip>
        <template #default="scope">
          <span>{{ parseTime(scope.row.maintenanceStartDate).slice(0,10) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="maintenanceEndDate" width="150" show-overflow-tooltip>
        <template #default="scope">
          <span>{{ parseTime(scope.row.maintenanceEndDate).slice(0,10) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目类型" align="center" prop="itemType" width="120" show-overflow-tooltip/>
      <el-table-column label="所属销售" align="center" prop="contractSale" width="80"/>
      <!--<el-table-column label="项目金额" align="center" prop="contractMoney" width="80"/>-->
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script setup name="Notice">
import { getAllItem } from "@/api/system/project.js"

const {proxy} = getCurrentInstance()

const noticeList = ref([])
const loading = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const currentRow = ref()

const data = reactive({
  queryParams: {
    page: 1,
    pageSize: 10,
    contractName: undefined,
    customerName: undefined,
    itemName: undefined,
    itemNo: undefined,
    shop: undefined,
  },
})

const { queryParams } = toRefs(data)

//表格单选
const handleCurrentChange = (val) => {
  currentRow.value = val
  console.log(currentRow.value)
}

/** 多选框选中数据 */
/*function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.dictId)
  single.value = selection.length != 1
  multiple.value = !selection.length
}*/

/** 查询公告列表 */
function getList() {
  loading.value = true
  getAllItem(queryParams.value).then(response => {
    noticeList.value = response.data.list
    total.value = response.data.total
    loading.value = false
  }).catch((err)=>{
    console.log(err)
    loading.value = false
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

//暴露给父组件的属性
defineExpose({currentRow})

getList()
</script>
